home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / newpass.zip / NEWPASS.C next >
Text File  |  1990-12-24  |  6KB  |  231 lines

  1.  
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <conio.h>
  6.  
  7. /**************************************************************************
  8.  *                                                                        *
  9.  *  NEWPASS.C  - Generate New Random Passwords for BBS's                  *
  10.  *                                                                        *
  11.  *         Written  December 23, 1990                                     *
  12.  *              by  David A. Scott                                        *
  13.  *                                                                        *
  14.  *  This program will generate random passwords of n length and print     *
  15.  *  them to either a file or the printer.  The user will be asked to      *
  16.  *  enter the length of the passwords and the number to generate.  The    *
  17.  *  program will then ask where to send the passwords to.  Either a       *
  18.  *  printer the screen can be used to display the new passwords.          *
  19.  *                                                                        *
  20.  *  Most BBS's would like for you to use a different password for each    *
  21.  *  BBS you use.  Sometimes this is hard to do.  But if you use a         *
  22.  *  communications program like Qmodem, then you have a place to keep     *
  23.  *  your passwords for each BBS.  So now you can generate a unique and    *
  24.  *  random password for each BBS you use.  This will keep your account    *
  25.  *  safe from those bad folks who figure out your password on one system. *
  26.  *  They might get one, but they'll not get them all!                     *
  27.  *                                                                        *
  28.  *  And now, since I'm in such a great mood, I hearby make this program   *
  29.  *  public domain.  It is offered as is.  I claim no responsibility for   *
  30.  *  any damage done by this program or modifications of it.  You may      *
  31.  *  use the source as you see fit as long as you do not use it in a       *
  32.  *  commercial program.  No money may be collected for this program.      *
  33.  *  It is free and should not cost any more than that.  Enjoy.....        *
  34.  *                                                                        *
  35.  *                                       -David Scott                     *
  36.  *                                                                        *
  37.  **************************************************************************/
  38.  
  39. #define TRUE  1
  40. #define FALSE 0
  41.  
  42. void showtitles(void);
  43. void get_parameters(void);
  44. void screen_output();
  45. void printer_output();
  46. int print(int retval);
  47. int quit(int retval);
  48. void cleanup(void);
  49.  
  50. int no_2_generate,pass_length;
  51.  
  52. int main()
  53. {
  54. int check;
  55.   showtitles();
  56.   do
  57.   {
  58.   get_parameters();
  59.   } while(quit(check));
  60. cleanup();
  61. }
  62.  
  63. void cleanup()
  64. {
  65. window(1,1,80,25);
  66. textcolor(LIGHTGRAY);
  67. textbackground(BLACK);
  68. clrscr();
  69. puts("Thanks for using NEWPASS!");
  70. puts("");
  71. }
  72.  
  73. int quit(retval)
  74. int retval;
  75. {
  76. char ch;
  77.  do
  78.  {
  79.  window(1,1,6,1);
  80.  textcolor(WHITE);
  81.  textbackground(RED);
  82.  cprintf("Quit?");
  83.  ch=getch();
  84.  } while(!strchr("YyNn",ch));
  85.  textcolor(BLACK);
  86.  textbackground(BLACK);
  87.  clrscr();
  88. retval = TRUE;
  89. if(toupper(ch) == 'Y') retval = FALSE;
  90. return retval;
  91. }
  92.  
  93. int print(retval)
  94. int retval;
  95. {
  96. char ch;
  97.  do
  98.  {
  99.  window(25,10,80,25);
  100.  textbackground(BLACK);
  101.  clrscr();
  102.  window(25,10,43,25);
  103.  textcolor(WHITE);
  104.  textbackground(RED);
  105.  cprintf("Printer or Screen?");
  106.  ch=getch();
  107.  } while(!strchr("PpSs",ch));
  108.  textcolor(BLACK);
  109.  textbackground(BLACK);
  110.  clrscr();
  111. retval = TRUE;
  112. if(toupper(ch) == 'P') retval = FALSE;
  113. return retval;
  114. }
  115.  
  116. void showtitles()
  117. {
  118. textcolor(LIGHTGRAY);
  119. textbackground(BLACK);
  120. clrscr();
  121. window(53,1,80,5);
  122. textcolor(LIGHTGRAY);
  123. textbackground(MAGENTA);
  124. cprintf("╔══════════════════════════╗");
  125. cprintf("║                          ║");
  126. cprintf("║                          ║");
  127. cprintf("╚══════════════════════════╝");
  128. textcolor(WHITE);
  129. gotoxy(4,2);
  130. cprintf("NEWPASS by David Scott");
  131. gotoxy(3,3);
  132. cprintf("Generate Random Passwords");
  133. }
  134.  
  135. void get_parameters()
  136. {
  137.  int check;
  138.  window(1,5,40,6);
  139.  textcolor(WHITE);
  140.  textbackground(BLUE);
  141.  clrscr();
  142.  
  143.     no_2_generate = NULL;
  144.     while(no_2_generate == NULL || no_2_generate > 99)
  145.     {
  146.     gotoxy(1,1);
  147.     cputs("                                      ");
  148.     gotoxy(2,1);
  149.     cputs("number of passwords to generate > ");
  150.     cscanf("%d",&no_2_generate);
  151.     }
  152.  
  153.     pass_length = NULL;
  154.     while(pass_length == NULL || pass_length > 15)
  155.     {
  156.     gotoxy(1,2);
  157.     cputs("                                      ");
  158.     gotoxy(2,2);
  159.     cputs("        length of each password > ");
  160.     cscanf("%d",&pass_length);
  161.     }
  162.  if(print(check))
  163.     {
  164.     screen_output();
  165.     }
  166.     else
  167.     {
  168.     printer_output();
  169.     }
  170. }
  171.  
  172.  
  173. void screen_output()
  174. {
  175.  int rand_number,i,j;
  176.  window(25,10,80,25);
  177.  textbackground(BLACK);
  178.  clrscr();
  179.  window(25,10,39+pass_length,25);
  180.  textcolor(WHITE);
  181.  textbackground(GREEN);
  182.  randomize();
  183.  for(i=0;i<no_2_generate;i++)
  184.      {
  185.      cprintf("Password #%2.0d = ",i+1);
  186.          for(j=0;j<pass_length;j++)
  187.          {
  188.          rand_number = random(25) + 65;
  189.          cprintf("%c",rand_number);
  190.          }
  191.      }
  192. }
  193.  
  194. void printer_output()
  195. {
  196.  int rand_number,i,j;
  197.  FILE *prtr;
  198.  char yn[2];
  199.  
  200.  prtr = fopen("prn","w");
  201.  while(prtr == NULL)
  202.     {
  203.     window(25,10,38,27);
  204.     textbackground(MAGENTA);
  205.     textcolor(YELLOW);
  206.     clrscr();
  207.     putchar(7);
  208.     cprintf("printer error!");
  209.     cprintf(" retry? (Y/N) ");
  210.     gets(yn);
  211.     if(toupper(yn) == 'N') return;
  212.     prtr = fopen("prn","w");
  213.     }
  214.  
  215.  fprintf(prtr,"\nNewPass -- by David Scott");
  216.  fprintf(prtr,"\nRandom Passwords\n\n");
  217.  randomize();
  218.  for(i=0;i<no_2_generate;i++)
  219.      {
  220.      fprintf(prtr,"\n\tPassword #%2.0d = ",i+1);
  221.          for(j=0;j<pass_length;j++)
  222.          {
  223.          rand_number = random(25) + 65;
  224.          fprintf(prtr,"%c",rand_number);
  225.          }
  226.      }
  227.  fprintf(prtr,"\n\nend of list");
  228.  fprintf(prtr,"%c %c",12,12);
  229.  fclose(prtr);
  230. }
  231.